<?php
class Calendar extends MY_Controller{
		
	function __construct(){
		parent::__construct();

		if(!$this->checkUserStatus()){
			redirect('login');
		}else{
			$this->aauth->update_activity();
		}

	}
	
	
	function index(){
		$data['toDoList'] = $this->get_tasks();
		$data['customers'] = customer::find('all');
		$data['title'] = $this->title('Calendier');
		$data['user'] = $this->aauth->get_user();
		$this->load->view($this->theme.'/header',$data);
		$this->load->view($this->theme.'/calendar/index');
		$this->load->view($this->theme.'/footer');


	}
	
	function getTasks()
	{
		if(!$_POST)
		{
			redirect("error_404");	
		}else{
			$doList = follow::find('all',array('conditions'=>array(' aauth_user_id = '.$this->aauth->get_user_id()),'order'=>'date_start asc'));
			$newList = array();
			foreach ($doList as $l){
				if($l->color == 'aqua'){
					$l->color = 'info';
				}
				$newList[] = array('title'=>$l->content,'start'=>date("D d M Y H:i:s O",strtotime($l->date_start)),'end'=>date("D d M Y H:i:s O",strtotime($l->date_end)),'backgroundColor'=>$l->color,'borderColor'=>$l->color,'url'=>site_url('properties/viewProperty').'/'.$l->property_id);
				
			}
			echo json_encode($newList);
		}
	}
	
}